<template>
  <div>
    <head-top routerName="task" title="今日任务"></head-top>
    <div class="content-wrap">
      <div class="total">
        <ul>
          <li>
            <div class="data">{{ PackageStatistics.Num }}</div>
            <div class="label">加速包总量</div>
          </li>
          <li>
            <div class="data">3000</div>
            <div class="label">今日产量</div>
          </li>
          <li>
            <div class="data">3000</div>
            <div class="label">昨日产量</div>
          </li>
        </ul>
      </div>
      <div class="nav">
        <ul>
          <li
            :class="indexOf === item.id ? 'current' : ''"
            v-for="item in nav"
            :key="item.id"
            @click="clickNav(item.id)"
          >
            {{ item.label }}
          </li>
        </ul>
      </div>
      <van-loading v-if="loading"  size="20" text-size="14">加载中...</van-loading>
      <div
        v-else
        class="list"
        v-for="(item, index) in PackageList"
        :key="index"
        @click="clickRouter(item)"
      >
        <div class="head">
          <div class="name">{{ item.packageName | formatFront }}</div>
          <div class="right">
            {{ nav.find((item) => item.id === indexOf).label }}
          </div>
          <div class="details">详情<van-icon name="arrow" /></div>
        </div>
        <div class="content">
          <ul>
            <li>
              <div class="label">每日产出</div>
              <div class="data">
                <span>{{ item.daily }}</span
                >金豆
              </div>
            </li>
            <li>
              <div class="label">释放周期</div>
              <div class="data">
                <span>{{ item.readingCycle }}</span
                >天
              </div>
            </li>
            <li>
              <div class="label">数量</div>
              <div class="data">
                <span>{{ item.packageIdNum }}</span
                >个
              </div>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { Icon, Loading } from "vant";
import { packageStatistics, packageStatus } from "@/api/task";
import HeadTop from "@/components/head";
export default {
  components: {
    [Icon.name]: Icon,
    [Loading.name]: Loading,
    HeadTop
  },
  data() {
    return {
      nav: [
        {
          label: "进行中",
          id: 1,
        },
        {
          label: "已完成",
          id: 0,
        },
      ],
      indexOf: 1,
      PackageList: [],
      PackageStatistics: [],
      loading:true
    };
  },
  filters: {
    formatFront(text) {
      const index = text.indexOf(" ");
      if (index !== -1) {
        return text.substring(0, index);
      } else {
        return text;
      }
    },
  },
  created() {
    packageStatistics().then((res) => {
      this.PackageStatistics = res.data.resultData[0];
    });
    this.getPackageStatus();
  },
  methods: {
    clickNav(id) {
      this.indexOf = id;
      this.getPackageStatus();
    },
    getPackageStatus() {
      const data = {
        pageNo: 0,
        pageSize: 30,
        status: this.indexOf,
      };
      this.PackageList = [];
      this.loading = true
      packageStatus(data).then((res) => {
        this.PackageList = res.data.resultData;
        this.loading = false
      });
    },
    clickRouter(query) {
      query.statusIndexOf = this.indexOf
      this.$router.push({
        name: "taskListDetails",
        query,
      });
    },
  },
};
</script>
<style lang="less" scoped>
.content-wrap {
  .total {
    padding-top: 17px;
    ul {
      display: flex;
      justify-content: space-around;
      align-items: center;
      list-style: none;
      margin: 0;
      padding: 0;
      height: 64px;
      box-shadow: 0px 0px 30px 0px rgba(0, 0, 0, 0.06);
      border-radius: 2px;
      li {
        text-align: center;
        .data {
          height: 25px;
          font-size: 18px;
          font-weight: 600;
          color: #333333;
          line-height: 25px;
        }
        .label {
          margin-top: 5px;
          height: 17px;
          font-size: 12px;
          font-weight: 400;
          color: #333333;
          line-height: 17px;
        }
      }
    }
  }
  .nav {
    margin-top: 20px;
    text-align: center;
    ul {
      display: inline-block;
      list-style: none;
      border-radius: 2px;
      border: 1px solid #979797;
      margin: 0;
      padding: 0;
      font-size: 0;
      li {
        display: inline-block;
        width: 115px;
        height: 38px;
        line-height: 38px;
        text-align: center;
        font-size: 14px;
        font-weight: 500;
        &.current {
          color: #ffffff;
          background: #333333;
        }
      }
    }
  }
  .list {
    margin-top: 13px;
    height: 100px;
    padding: 0 14px;
    box-shadow: 0px 0px 30px 0px rgba(0, 0, 0, 0.06);
    border-radius: 1px;
    .head {
      display: flex;
      align-items: center;
      height: 42px;
      border-bottom: 1px solid #f1f1f1;
      .name {
        flex: 1;
        font-size: 16px;
        font-weight: 500;
        color: #333333;
        line-height: 22px;
      }
      .details {
        flex: 1;
        font-size: 12px;
        display: flex;
        align-items: center;
        justify-content: flex-end;
      }
      .right {
        flex: 1;
        text-align: center;
        font-size: 12px;
        font-weight: 400;
        color: #fe4b08;
      }
    }
    .content {
      ul {
        list-style: none;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0;
        margin: 0;
        height: 57px;
        li {
          flex: 1;
          text-align: center;
          font-size: 12px;
          font-weight: 400;
          color: #333333;
          line-height: 17px;
          span {
            color: #fe4b08;
          }
        }
      }
    }
  }
}
</style>